// cookie函数封装

/**
 * @desc 获取cookie
 * @param {*} name 存储的cookie名
 */
export function getCookie(name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if (arr = document.cookie.match(reg))
    return unescape(arr[2]);
  else
    return null;
}

/**
 * @desc 设置cookie
 * @param {*} c_name 要存储的cookie名
 * @param {*} value 要存储的值
 * @param {*} expiredays 要保存的天数
 */
export function setCookie(c_name, value, expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
};

/**
 * @desc 删除cookie
 * @param {*} name 要删除的cookie名
 */
export function delCookie(name) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval = getCookie(name);
  if (cval != null)
    document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
};